<?php
set_include_path("../include;include");
require_once '/model/Member.php';
require_once '/dao/ParticipantDAO.php';

class Participant {
	private $id;
	private $firstname;
	private $lastname;
	private $member;

	public function __construct() {

	}

	public static function createNew(string $firstname, string $lastname) {
		$instance = new self();
		$instance->firstname = $firstname;
		$instance->lastname = $lastname;
		return $instance;
	}

	public static function loadParticipant(integer $participantId) {
		$dao = ParticipantDAO::getInstance();

		$participant = new self();
		$participant->id = $participantId;
		$participant->firstname = $dao->getFirstnameByParticipantId($id);
		$participant->lastname = $dao->getLastnameByParticipantId($id);
		$participant->member = Member::loadMember($dao->getMemberIdByParticipantId($id));

		return $participant;
	}

	public static function getAllParticipantsFor(Registration $registration) {
		$dao = ParticipantDAO::getInstance();

		return $dao->getAllParticipantsByRegistrationId($registration->getId());
	}

	public function load(integer $participantId) {
		$dao = ParticipantDAO::getInstance();

		$this->id = $participantId;
		$this->firstname = $dao->getFirstnameByParticipantId($id);
		$this->lastname = $dao->getLastnameByParticipantId($id);
		$this->member = Member::loadMember($dao->getMemberIdByParticipantId($id));
	}

	public function save() {
		$dao = ParticipantDAO::getInstance();

		$part_id = $dao->save($this);
		$this->id = $part_id;
		return $part_id;
	}

	/* Getters and setters */

	public function getId() {
		return $this->id;
	}

	public function setId(integer $id) {
		$this->id = $id;
	}

	public function getFirstname() {
		return $this->firstname;
	}

	public function setFirstname(string $firstname) {
		$this->firstname = $firstname;
	}

	public function getLastname() {
		return $this->lastname;
	}

	public function setLastname(string $lastname) {
		$this->lastname = $lastname;
	}

	public function getMember() {
		return $this->member;
	}

	public function setMember(Member $member) {
		$this->member = $member;
	}

	public function __toString() {
		return $this->getFirstname() . " " . $this->getLastname();
	}

}